#include #include #include using namespace std; void print72(char *p); void main(){ // not a c string char s[3]; s[0] = 'a'; s[1] = 'b'; s[2] = 'c'; cout << s << endl; // is a c string char fixed[4]; fixed[0] = 'a'; fixed[1] = 'b'; fixed[2] = 'c'; fixed[3] = '\0'; cout << fixed << endl; // string pointer char *p = s; cout << p << endl; p = fixed; cout << p << endl; // string literal to function print72("My Message"); // create an array size 4 char x[] = "012"; cout << x[0] << endl; cout << x[1] << endl; cout << x[2] << endl; cout << x[3] << endl; // not valid //s = fixed; //cout << s << endl; // valid for c strcpy(x, fixed); cout << x << endl; string cpps("init"), cs = "final"; cout << cpps << " " << cs << endl; if(cpps == cs)cout << " cpps == cs " << endl; if(cpps <= cs)cout << " cpps <= cs " << endl; if(cpps >= cs)cout << " cpps >= cs " << endl; cpps = cs; if(cpps == cs)cout << " cpps == cs " << endl; cout << cpps << endl; // copy constructor string ape(cs), tree("tree"), banana("banana"); cout << ape << endl; cout << ape.length() << endl; cout << ape[3] << endl; ape = tree + " and a " +banana; cout << ape << endl; // cin parses on a space string fn, ln; cout << " enter your name (first and last)" << endl; cin >> fn; cout << fn; cin >> ln; cout << " " << ln << endl; // cin parses on a change in type int n,d; char line; cout << "enter a fraction like 1/2" << endl; cin >> n >> line >> d; cout << n << line << d << endl; } void print72(char *p){ cout << p << endl; cout << 72 << endl; }